<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >查询</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :disabled="single"
          @click="check_all = true"
          v-hasPermi="['putStorage:proMatFinish:allCredit']"
        >
          一键入库
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-circle-check"
          size="mini"
          :disabled="single"
          @click="show(1)"
          v-hasPermi="['putStorage:proMatFinish:post']"
        >
          过账
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="show(2)"
          v-hasPermi="['putStorage:proMatFinish:post']"
        >
          撤回开单
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport(1)"
          v-hasPermi="['putStorage:proMatStart:export']"
        >
          EXCEL
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport(2)"
          v-hasPermi="['putStorage:proMatStart:export']"
        >
          子项EXCEL
        </el-button>
      </el-col>
      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#bb0331">通过</Tag>
      <Tag type="dot" size="default" color="#0323af">检验</Tag>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <!-- 头表Table -->
    <el-table
      @scrollBottom="load"
      highlight-current-row
      border
      stripe
      v-loading="loading"
      :height="tableH"
      :cell-style="iCellStyle2"
      @row-click="clickRtm"
      :data="proMatStartList"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" type="index" width="40" align="center" />
      <el-table-column
        label="退料单号"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rtmDjbh"
      />
      <el-table-column
        label="退料日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rtmTlrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rtmTlrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="退料部门"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rtmBmdm"
      />
      <el-table-column
        label="退料仓库"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rtmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.rtmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rtmDesc"
      />
      <el-table-column
        label="撤回原因"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rtmNgdesc"
      />
      <el-table-column
        label="开单人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rtmJlry"
      />
      <el-table-column
        label="开单日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rtmJlrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rtmJlrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rtmShry"
      />
      <el-table-column
        label="审核日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rtmShrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rtmShrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="rtmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="rtmGzrq"
        width="180"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rtmGzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="生产退料入库单"
        align="center"
        width="150"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="small"
            type="text"
            icon="el-icon-s-promotion"
            @click="printHandle(scope.row)"
            v-hasPermi="['putStorage:proMatFinish:DY']"
          >
            单据打印
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!--    需要打印的东西-->
    <el-dialog
      v-model="printDiag"
      :close-on-click-modal="false"
      width="757px"
      append-to-body
    >
      <section ref="print">
        <el-table
          border
          style="width: 100%"
          :data="rtdDetList"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column label="武汉市衡德实业有限公司生产退料入库单">
            <el-table-column label="车间" width="135">
              <el-table-column label="退货仓库" width="135">
                <el-table-column
                  label="物料编码"
                  align="center"
                  prop="rtdWldm"
                  width="135"
                ></el-table-column>
              </el-table-column>
            </el-table-column>
            <el-table-column :label="printDjbh" width="300">
              <el-table-column :label="printCkdm" width="300">
                <el-table-column
                  label="物料名称规格"
                  align="center"
                  prop="itmPmgg"
                  width="300"
                ></el-table-column>
              </el-table-column>
            </el-table-column>
            <el-table-column :label="printGzry" width="120">
              <el-table-column label="单据编号" width="120">
                <el-table-column
                  label="单位"
                  :show-overflow-tooltip="true"
                  width="60"
                  align="center"
                  prop="itmDw"
                >
                  <template #default="scope">
                    <dict-tag
                      :options="unitFlagOptions"
                      :value="scope.row.itmDw"
                    />
                  </template>
                </el-table-column>
                <el-table-column
                  label="数量"
                  align="center"
                  prop="rtdRksl"
                  width="60"
                ></el-table-column>
              </el-table-column>
            </el-table-column>
            <el-table-column :label="printRkrq" width="100">
              <el-table-column :label="printDdbh" width="100">
                <el-table-column label="备注" width="160"></el-table-column>
              </el-table-column>
            </el-table-column>
          </el-table-column>
        </el-table>
        <div
          slot="footer"
          class="dialog-footer no-print"
          style="margin-top: 10px; display: flex; justify-content: flex-end"
        >
          <el-button type="primary" class="no-print" @click="printData"
            >打 印</el-button
          >
          <el-button class="no-print" @click="cancel">取 消</el-button>
        </div>
      </section>
    </el-dialog>
    <!-- 子项Table   -->
    <el-table
      border
      stripe
      highlight-current-row
      :height="tableHChild"
      :data="rtdDetList"
      :cell-style="iCellStyle"
      :header-cell-style="{ 'text-align': 'center', padding: '2px' }"
    >
      <el-table-column width="30px" label="#" type="index" align="center" />
      <el-table-column
        width="150px"
        label="物料代码"
        align="center"
        prop="rtdWldm"
      />
      <el-table-column
        width="150px"
        label="客户编码"
        align="center"
        prop="itmCustwldm"
      />
      <el-table-column
        width="60px"
        label="单位"
        :show-overflow-tooltip="true"
        align="center"
        prop="itmDw"
      >
        <template #default="scope">
          <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
        </template>
      </el-table-column>
      <el-table-column
        width="90px"
        label="储位信息"
        :show-overflow-tooltip="true"
        align="center"
        prop="rtdCwdm"
      >
        <template #default="scope">
          <dict-tag :options="cWOptions" :value="scope.row.rtdCwdm" />
        </template>
      </el-table-column>
      <el-table-column
        width="90px"
        label="最小包装"
        align="center"
        prop="itmMinbz"
      />
      <el-table-column
        width="90px"
        label="包装数量"
        align="center"
        prop="rtdBzsl"
      />
      <el-table-column
        width="90px"
        label="申请数量"
        align="center"
        prop="rtdSqsl"
      />
      <el-table-column
        width="90px"
        label="入库数量"
        align="center"
        prop="rtdRksl"
      />
      <el-table-column
        width="90px"
        label="入库人员"
        align="center"
        prop="rtdRkry"
      />
      <el-table-column
        width="90px"
        label="入库日期"
        align="center"
        prop="rtdRkrq"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.rtdRkrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="品名规格" align="center" prop="itmPmgg" />
      <el-table-column
        label="操作"
        align="center"
        width="80px"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="small"
            type="text"
            :disabled="single"
            v-hasPermi="['putStorage:proMatFinish:confirm']"
            @click="handleCheckStorage(scope.row)"
          >
            入库确认
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="450px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="88px"
      >
        <el-col :span="24">
          <el-form-item label="建立日期">
            <el-date-picker
              v-model="daterangeRtmJlrq"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              type="daterange"
              range-separator="-"
              :picker-options="pickerOptions"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="['00:00:00', '23:59:59']"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="退料单号" prop="rtmDjbh">
            <el-input
              v-model="queryParams.rtmDjbh"
              style="width: 240px"
              placeholder="请输入退料单号"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="入库仓库" prop="rtmCkdm">
            <el-select
              v-model="queryParams.rtmCkdm"
              style="width: 240px"
              clearable
              filterable
              placeholder="请选择仓库"
            >
              <el-option
                v-for="item in storageOptions"
                :key="item.dictValue"
                :label="item.dictLabel"
                :value="item.dictValue"
              ></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item prop="rtmZtbz">
            <RadioGroup v-model="queryParams.rtmZtbz">
              <Radio style="margin-left: 100px" label="2">未过账</Radio>
              <Radio style="margin-left: 20px" label="5">已过账</Radio>
              <Radio style="margin-left: 20px" label="6">全 部</Radio>
            </RadioGroup>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
    <Modal v-model="check_all" draggable scrollable width="300">
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认</span>
      </p>
      <div style="text-align: center">
        <p>
          确认将【入库单号:{{
            this.clickRtmMstr.rtmDjbh
          }}】的材料进行一键入库吗？
        </p>
      </div>
      <div slot="footer">
        <Button type="success" size="large" long @click="handleAllCredit"
          >一键入库</Button
        >
      </div>
    </Modal>
    <Modal v-model="check_back" draggable scrollable width="300">
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>撤回</span>
      </p>
      <div style="text-align: center">
        <p>
          确认将【入库单号:{{
            this.clickRtmMstr.rtmDjbh
          }}】的材料进行撤回开单吗？
        </p>
      </div>
      <div slot="footer">
        <Button type="success" size="large" long @click="handleBack"
          >撤回开单</Button
        >
      </div>
    </Modal>
    <!-- 过账 -->
    <Modal v-model="check_post" draggable scrollable width="300">
      <p slot="header" style="color: #f60; text-align: center">
        <Icon type="ios-information-circle"></Icon>
        <span>确认</span>
      </p>
      <div style="text-align: center">
        <p>
          确认将【入库单号：{{ clickRtmMstr.rtmDjbh }}】的材料进行过账作业吗？
        </p>
        <p>一旦操作无法更改，系统库存将会增加，请谨慎操作。</p>
      </div>
      <div slot="footer">
        <Button type="success" size="large" long @click="handleChange(6, 1)"
          >过账</Button
        >
      </div>
    </Modal>
    <!-- 入库确认 -->
    <el-dialog
      title="入库确认"
      v-model="check_check"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form ref="form" label-width="88px" :model="form">
        <el-col :span="12">
          <el-form-item label="退料单号" prop="rtdDjbh">
            <el-input v-model="form.rtdDjbh" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="rtdWldm">
            <el-input v-model="form.rtdWldm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="品名规格" prop="itmPmgg">
            <el-input v-model="form.itmPmgg" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="存放位置" prop="rtdCwdm">
            <el-input v-model="form.rtdCwdm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请数量" prop="rtdSqsl">
            <el-input v-model="form.rtdSqsl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="包装数量" prop="rtdBzsl">
            <el-input v-model="form.rtdBzsl" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="最小包装" prop="itmMinbz">
            <el-input v-model="form.itmMinbz" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="入库数量" prop="rtdRksl">
            <el-input v-model="form.rtdRksl" type="number" @input="mxRksl" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handlePost">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listProMat,
  exportProMat,
  listRtdDet,
  updateProMat,
  rtdDetById,
  updRtdDet,
  allCredit,
  backFinish,
} from "@/api/putStorage/proMatStart";
import { getAll, getstorageType } from "@/api/repertory/Storage";
import { printOrder } from "@/utils/ruoyi";

export default {
  name: "ProMatFinish",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      clickRtmMstr: {},
      tableH: (document.body.clientHeight - 130) / 2,
      tableHChild: (document.body.clientHeight - 280) / 2,
      // 非单个禁用
      single: true,
      //检验、过账、撤回
      check_check: false,
      check_post: false,
      check_back: false,
      //撤回理由
      backReason: null,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      //所有存储仓库
      allStorageOptions: [],
      storageOptions: [],
      //单位字典
      unitFlagOptions: [],
      //默认储位字典
      cWOptions: [],
      // 总条数
      total: 0,
      sqslMx: 0,
      //form
      form: {},
      // 生产退料入库表格数据
      proMatStartList: [],
      //生产退料入库详细表数据
      rtdDetList: [],
      printDiag: false,
      // 弹出层标题
      printDjbh: null,
      printDdbh: null,
      printGzry: null,
      printType: null,
      printRkrq: null,
      printCkdm: null,
      printCsmc: null,
      check_all: null,

      title: "",
      // 是否显示弹出层
      open: false,
      // 建立日期时间范围
      daterangeRtmJlrq: [
        new Date(new Date().getFullYear(), new Date().getMonth() - 1),
        this.$moment().endOf("month").toDate(),
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        rtmDjbh: null,
        rtmZtbz: "2",
        rtmJlrq: null,
      },
      //日期初始化
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    this.getList();
    getAll().then((response) => {
      this.allStorageOptions = response.data;
      for (let item of this.allStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });
    //单位
    this.getDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
    //存放位置
    getAll().then((response) => {
      this.cWOptions = response.data;
      for (let item of this.cWOptions) {
        item.dictLabel = item.storageDefaultstorage;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });
    getstorageType("0").then((response) => {
      this.storageOptions = response.data;
      for (let item of this.storageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });
  },
  methods: {
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.rtdRksl) {
        return "color:#bb0331";
      }
    },
    iCellStyle2: function ({ row, column, rowIndex, columnIndex }) {
      //提交
      if (row.rtmZtbz == "1" && row.rtmTjflag == "1") {
        return "color:#0fac09";
      } else if (row.rtmTjflag == "1" && row.rtmZtbz == "6") {
        return "color:#bb0331";
      } else if (row.rtmTjflag == "1" && row.rtmZtbz == "2") {
        return "color:#0323af";
      }
    },
    /** 查询生产退料入库列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeRtmJlrq && "" != this.daterangeRtmJlrq) {
        this.queryParams.params["beginRtmJlrq"] = this.moment(
          this.daterangeRtmJlrq[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endRtmJlrq"] = this.moment(
          this.daterangeRtmJlrq[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.queryParams.page = 1;
      listProMat(this.queryParams).then((response) => {
        this.proMatStartList = [];
        this.rtdDetList = [];
        this.proMatStartList = this.proMatStartList.concat(response.rows);
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRtm(row);
        } else if (
          this.proMatStartList != null &&
          this.proMatStartList.length > 0
        ) {
          this.clickRtm(this.proMatStartList[0]);
        }
      });
    },
    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 20;
        this.queryParams.pageNum++;
        listProMat(this.queryParams).then((response) => {
          this.proMatStartList = this.proMatStartList.concat(response.rows);
          this.total = response.total;
          this.loading = false;
        });
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.printDiag = false;
      this.openSearch = false;
      this.check_check = false;
      this.reset();
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.proMatStartList = [];
      this.getList();
      this.openSearch = false;
    },
    // 表单重置
    reset() {
      this.form = {
        rtdId: null,
        rtdDjbh: null,
        rtdWldm: null,
        itmPmgg: null,
        itmDw: null,
        rtdCwdm: null,
        itmMinbz: null,
        rtdBzsl: null,
        rtdSqsl: null,
        rtdRksl: null,
        rtdRkry: null,
        rtdRkrq: null,
      };
      this.resetForm("form");
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeRtmJlrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    printHandle(a) {
      /*      for (let i = 0; i < this.allStorageOptions.length; i++) {
        if (this.allStorageOptions[i].dictValue == a.rtmCkdm) {
          this.printCkdm = this.allStorageOptions[i].dictLabel
          break
        }
      }
      this.printDjbh = a.rtmBmdm
      this.printGzry = a.rtmTlrq
      this.printRkrq = a.rtmJlry
      this.printDdbh = a.rtmDjbh
      this.printDiag = true*/
      printOrder(
        "/putStorageData/proMat/exportIncomingGoodsTemplate",
        a,
        "生产退料入库单据"
      );
    },
    printData() {
      this.$print(this.$refs.print).dom.ownerDocument.title =
        "武汉市衡德实业有限公司";
    },
    /** 单据单击事件*/
    clickRtm(row) {
      if (row != null) {
        this.clickRtmMstr = row;
        this.single = row == null || row.rtmZtbz != 2 || row.rtmTjflag != 1;
        this.getListRtdDet(row.rtmDjbh);
      }
    },
    getListRtdDet(rtmDjbh) {
      listRtdDet(rtmDjbh).then((res) => {
        this.rtdDetList = res.data;
      });
    },
    handleSearch() {
      this.reset();
      this.title = "查询生产退料入库";
      this.openSearch = true;
    },
    /** 过账操作按钮 */
    handleChange(ztbz, flag) {
      const data = {
        rtmId: this.clickRtmMstr.rtmId,
        rtmZtbz: ztbz,
        rtmTjflag: flag,
        rtmNgdesc: this.backReason,
        rtmGzry: this.$store.state.user.nickName,
        rtmGzrq: new Date(),
      };
      updateProMat(data).then((res) => {
        this.msgSuccess("过账成功~");
        this.check_post = false;
        this.getList();
      });
    },
    is_empty() {
      for (let i of this.rtdDetList) {
        if (i.rtdRksl == null || i.rtdRksl == 0) return true;
      }
      return false;
    },
    //一键入库
    handleAllCredit() {
      allCredit(this.clickRtmMstr.rtmDjbh).then((res) => {
        this.check_all = false;
        this.msgSuccess("一键入库物料成功");
        this.getList();
      });
    },
    show(e) {
      if (this.clickRtmMstr.rtmZtbz == 6) {
        this.$Modal.warning({
          title: "提示",
          content: "该单据已过账，不允许此操作",
        });
      } else if (this.is_empty() && e == 1) {
        this.$Modal.warning({
          title: "提示",
          content: "存在为确认入库数量的材料，不允许此操作",
        });
      } else {
        if (e == 1) {
          this.check_post = true;
        } else {
          this.check_back = true;
        }
      }
    },
    /** 过账撤回 */
    handleBack() {
      backFinish(this.clickRtmMstr.rtmDjbh).then((res) => {
        this.check_back = false;
        this.msgSuccess("撤回开单物料成功");
        this.getList();
      });
    },
    /** 入库确认-模态 */
    handleCheckStorage(row) {
      // console.log(row)
      this.sqslMx = row.rtdSqsl;
      console.log(this.sqslMx);
      rtdDetById(row.rtdId).then((res) => {
        this.form = res.data;
        this.check_check = true;
      });
    },
    //入库确认 入库数量范围
    mxRksl(a) {
      if (a > this.sqslMx) {
        this.form.rtdRksl = this.sqslMx;
      }
      if (a < 0) {
        this.form.rtdRksl = 0;
      }
    },
    /** 入库确认-提交 */
    handlePost() {
      if (this.form.rtdRksl != null && this.form.rtdRksl > 0) {
        const data = {
          rtdId: this.form.rtdId,
          rtdRksl: this.form.rtdRksl,
          rtdRkry: this.$store.state.user.nickName,
          rtdRkrq: new Date(),
        };
        updRtdDet(data)
          .then((res) => {
            this.getListRtdDet(this.form.rtdDjbh);
            this.msgSuccess("入库确认成功~");
            this.check_check = false;
            this.reset();
          })
          .catch(() => {
            this.msgError("入库确认失败~");
          });
      } else {
        this.msgError("入库数量输入不合法,请检查~");
      }
    },
    /** 导出按钮操作 */
    handleExport(index) {
      if (index == 2 && this.rtmDjbhs == null) {
        this.msgError("导出子项前,请先选择单据");
        return;
      }
      let queryParams = this.queryParams;
      queryParams.index = index;
      queryParams.rtmDjbh = this.rtmDjbhs;
      exportProMat(queryParams).then((response) => {
        this.download(response.msg);
      });
    },
  },
};
</script>

<style lang="scss" scoped></style>
